//
//  WBNavigationController.swift
//  WeiBo
//
//  Created by 今代科技 on 2017/10/16.
//  Copyright © 2017年 GZY. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

  
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的 NavigationBar
//        navigationBar.isHidden = true
        self.interactivePopGestureRecognizer?.delegate = nil
        self.navigationBar.isTranslucent = false
        self.navigationBar.tintColor = UIColor.orange
        //设置标题栏字体颜色
        navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.darkGray]
        
    }
    // 重写push方法, 所有的push 动画都会调用
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        // 如果不是栈底控制器才需要隐藏, 根控制器不需要处理
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
//            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.zy_Item(withIcon: "navigationbar_back_withtext", highIcon: "navigationbar_back_withtext_highlighted", target: self, action: #selector(back))
            if let vc = viewController as? WBBaseViewController {
                var title = "返回"
                if childViewControllers.count == 1 {
                    // title显示首页标题
                    title = childViewControllers.first?.title ?? "返回"
                }
//                vc.navigationItem.leftBarButtonItem = UIBarButtonItem.zy_back(with: UIImage.init(named: "navigationbar_back_withtext"), title: title, target: self, selector: #selector(back), titleColor: nil)
//                vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(back))
                vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(back), isBack: true)
            }
            
        }
       
        super.pushViewController(viewController, animated: true)
    }
    @objc private func back () {
//        self.popViewController(animated: true)
        popViewController(animated: true)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    

}
